package pwd.allen.aio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
import java.util.Iterator;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * AIO客户端
 */
public class Client {

    /**
     * 启动客户端测试
     * @throws IOException
     */
    public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
        AsynchronousSocketChannel channel = AsynchronousSocketChannel.open();
        channel.connect(new InetSocketAddress("127.0.0.1",8888)).get();
        ByteBuffer buffer = ByteBuffer.wrap("中文,你好".getBytes());
        Future<Integer> future = channel.write(buffer);

        future.get();
        System.out.println("send ok");
    }

}
